
public class twoSum {
	
	public void tester()
	{
		int [] input = {3,2,4};
		int [] output = twoSum2(input, 6);
		System.out.println(output[0]+" "+ output[1]);
	}
	
    public int[] twoSum2(int[] numbers, int target) {
        int r1 = 0, r2 = 0;
        int [] n2 = new int[numbers.length];
        System.arraycopy(numbers, 0, n2, 0, numbers.length);
        int temp;
        quicksort(numbers, 0, numbers.length-1);
        for(int i = 0 ; i < numbers.length - 1 ; i ++)
        {
            temp = bs(numbers, i+1, target - numbers[i]);
            if(temp != -1)
            {
                r1 = i;
                r2 = temp;
                System.out.println(r1+" "+ r2);
                break;
            }
        }
        
        int [] result = new int[2];
        
        result[0] = ls(n2, -1, numbers[r1]) + 1;
        
        System.out.println();
        
        result[1] = ls(n2, result[0]-1, numbers[r2]) + 1;
        
        System.out.println("re: "+result[0]+" "+result[1]);
        
        if(result[0] < result[1])
            return result;
        else
        {
            int xx = result[0];
            result[0] = result [1];
            result[1] = xx;
            return result;
        }
    }
    
    public int ls(int [] a, int s, int t)
    {
        for(int i = 0; i < a.length ; i++)
        {
        	System.out.println("i: "+i+" "+a[i]);
            if(t == a[i] && i != s) {
            return i;}
            // System.out.println(a[i]);
        }
        return -100;
    }
    
    public int bs(int[] a, int s, int t) {
        int lo = s;
        int hi = a.length - 1;
        while (lo <= hi) {
            int mid = lo + (hi - lo) / 2;
            if (t < a[mid]) hi = mid - 1;
            else if (t > a[mid]) lo = mid + 1;
            else return mid;
        }
        return -1;
    }
    
    int binarySearch(int A[], int s, int t) 
    {
        int start = s;
        int end = A.length;
        while (end - start > 1) {
            int mid = (end - start) / 2 + start;
            if (A[mid] > t) {
            end = mid;
            } else {
                start = mid;
            }
        }
        if(A[start] == t) return start;
        else return -1;
    }   
    
    public void quicksort(int [] list, int start, int end) 
	{
		int pivot = list[(start + end) / 2];
		int a = start ;
		int b = end ;
		int temp = 0 ;
		
		while(a <= b)
		{
			while(list[a] < pivot)
				a++ ;
			while(list[b] > pivot)
				b-- ;
			if(a <= b)
			{
				temp = list[a] ;
				list[a] = list[b] ;
				list[b] = temp ;
				a++ ;
				b-- ;
			}
		}
		if(start < a-1)
			quicksort(list, start, a-1 ) ;
		if(a < end)
			quicksort(list, a, end ) ;
	}
}